package com.hd.view.action;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.hd.common.Common;
import com.hd.common.DataPage;
import com.hd.persistence.model.AcceptTreatmentCase;
import com.hd.persistence.model.Customer;
import com.hd.persistence.model.Machine;
import com.hd.persistence.model.Person;

/**
 * 受理单Action
 * @author jiaoyang
 *
 */
public class ResolveAction extends BaseAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private AcceptTreatmentCase acceptTreatmentCase;
	/*受理时间*/
	private String acceptTreatmentTime;
	/*受理人*/
	private List<Person> accepters;
	/*list所有客户*/
	private List<Customer> customers;
	/*list所有机型*/
	private List<Machine> machines;
	/*查询出的受理单*/
	private DataPage<AcceptTreatmentCase> acceptTreatmentCases;
	/*客户Id*/
	private String customerId;
	/**
	 * 增加受理单
	 * 
	 * @return
	 * @throws Exception
	 */
	public String addNewResolve() throws Exception{
		/*列出所有受理员*/
		accepters = memberManager.listPerson(-1, false);
		/*列出所有客户*/
		customers = purchaseManager.listCustomers();
		/*列出所有机器*/
		machines = memberManager.listMachine();
		return SUCCESS;
	}
	
	/**
	 * 保存受理单
	 * 
	 * @return
	 * @throws Exception
	 */
	public String saveNewResolve() throws Exception{
		Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		long  d = ((Date)format.parseObject(acceptTreatmentTime)).getTime();
		acceptTreatmentCase.setAcceptTreatmentTime(d); 
		acceptTreatmentCase.setCreateTimestamp(System.currentTimeMillis());
		repairManager.saveAcceptTreatmentCase(acceptTreatmentCase);
		
		statusTemp = true;
		return SUCCESS;
	}
	
	/**
	 * 查询受理单
	 * (根据客户名查询受理单)
	 * @return
	 * @throws Exception
	 */
	public String listResolves() throws Exception{
		accepters = memberManager.listPerson(-1,false);//所有受理人
		
		customers = purchaseManager.listCustomers();//所有客户
		
		if(acceptTreatmentCase == null){
			acceptTreatmentCase = new AcceptTreatmentCase();
		}
		acceptTreatmentCases = repairManager.pageQueryAcceptTreatmentCases(acceptTreatmentCase.getUnitName(), acceptTreatmentCase.getAcceptTreatmenter(), Common.String2Date(acceptTreatmentTime), getCurrentPage(), pageSize);
		
		setTotalPage(acceptTreatmentCases.getTotalPageCount());
		return SUCCESS;
	}
	
	/**
	 * 查看受理单
	 * 
	 * @return
	 * @throws Exception
	 */
	public String viewResolve() throws Exception{
		return SUCCESS;
	}

	
/*===============get,set方法==============================================*/
	public AcceptTreatmentCase getAcceptTreatmentCase() {
		return acceptTreatmentCase;
	}
	
	public void setAcceptTreatmentCase(AcceptTreatmentCase acceptTreatmentCase) {
		this.acceptTreatmentCase = acceptTreatmentCase;
	}

	public String getAcceptTreatmentTime() {
		return acceptTreatmentTime;
	}

	public void setAcceptTreatmentTime(String acceptTreatmentTime) {
		this.acceptTreatmentTime = acceptTreatmentTime;
	}

	public List<Person> getAccepters() {
		return accepters;
	}

	public void setAccepters(List<Person> accepters) {
		this.accepters = accepters;
	}

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public List<Machine> getMachines() {
		return machines;
	}

	public void setMachines(List<Machine> machines) {
		this.machines = machines;
	}

	public DataPage<AcceptTreatmentCase> getAcceptTreatmentCases() {
		return acceptTreatmentCases;
	}

	public void setAcceptTreatmentCases(
			DataPage<AcceptTreatmentCase> acceptTreatmentCases) {
		this.acceptTreatmentCases = acceptTreatmentCases;
	}

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	
}
